import axios from 'axios'
// const baseURL = import.meta.env.VITE_MODE != 'dev' ? import.meta.env.VITE_API_HOST + "/api" : '/api'
const baseURL = '/api'


const r = axios.create({
    baseURL: baseURL,
    timeout: 30000
})
r.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么
    let token = localStorage.getItem("token");
    if (token) {
        if (!config.headers) {
            config.headers = {};
        }
        config.headers.Authorization = token;

    }
    return config;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});
r.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response.data
}, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
});
export function request(config) {
    return r.request(config)
}